// components/find/find.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    nav:[
      { name:'每日推荐',
        url:'../../icon/tuijian.png',
        key:1
      },
      {
        name:'歌单',
        url:'../../icon/gedan.png',
        key:2
      },
      {
        name:'排行榜',
        url:'../../icon/paixingbang.png',
        key:3
      },
      {
        name:'电台',
        url:'../../icon/music.png',
        key:4
      },
      {
        name:'直播',
        url:'../../icon/zhibo.png',
        key:5
      }
    ],
    tuijiangedan:[]
  },
  created(){
    this.getBanner();
    this.getTuijiangedan();
  },
  /**
   * 组件的方法列表
   */
  methods: {
    getBanner(){
      let _that = this;
  
      wx.request({
        url: 'http://musicapi.leanapp.cn/banner',
        data: {},
        header: {'content-type':'application/json'},
        method: 'GET',
        dataType: 'json',
        responseType: 'text',
        success: (data) => {
         
          if(data.data.code == 200){
           
            _that.setData({
              banners:data.data.banners
            })
          }
        },
        fail: () => {},
        complete: () => {}
      });
    },
    getTuijiangedan(){
      let _that = this;
  
      wx.request({
        url: 'http://musicapi.leanapp.cn/personalized',
        data: {},
        header: {'content-type':'application/json'},
        method: 'GET',
        dataType: 'json',
        responseType: 'text',
        success: (data) => {
         
          if(data.data.code == 200){
            
            let result=[];
            for(let i =0 ;i<6;i++){
              result.push(data.data.result[i])
            }
            _that.setData({
              tuijiangedan:result
            })
          }
        },
        fail: () => {},
        complete: () => {}
      });
    },
    navTo(e){
      let key = e.target.dataset.index;
      switch (key) {
        case 1:
          wx.navigateTo({
            url: '../tuijian/tuijian'
          });
          break;
      
        default:

          break;
      }
    }
  }
})
